package spring.demo.controller;

import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import spring.demo.entity.Student;
import spring.demo.mapper.StudentMapper;

@RestController
@RequestMapping("/student")
public class StudentController {

    private static final Logger logger = LoggerFactory.getLogger(StudentController.class);

    @Autowired
    private StudentMapper studentMapper;

    @RequestMapping("/list")
    public List<Student> getAllStudents() {
        return studentMapper.listAll();
    }

    @RequestMapping("/id/{id}")
    public Student findStudentById(@PathVariable("id") String name) {
        return studentMapper.findUserById(name);
    }

    @RequestMapping("/class/{className}")
    public List<Student> findStudentByClass(@PathVariable("className") String className) {
        return studentMapper.findUserByClass(className);
    }

    @RequestMapping("/name/{name}")
    public List<Student> findStudentByName(@PathVariable("name") String name) {
        return studentMapper.findUserByName(name);
    }
}
